from datetime import datetime

from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from sqlalchemy.orm import relationship

from .database import Base


class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, autoincrement=True)
    nick_name = Column(String)
    avatar = Column(String)
    wx_open_id = Column(String, unique=True, index=True)
    wx_union_id = Column(String, unique=True, index=True)
    wx_session_key = Column(String)
    wx_js_code = Column(String)
    invite_code = Column(String, unique=True, index=True)
    up_time = Column(Integer)

    interests = relationship("Interest", uselist=False, backref="users")


class Interest(Base):
    __tablename__ = "interests"

    id = Column(Integer, primary_key=True, autoincrement=True)
    user_id = Column(Integer, ForeignKey("users.id"))
    is_viper = Column(Integer)
    points = Column(Integer)
    free_count = Column(Integer)
    status = Column(Integer)


class Invitation(Base):
    __tablename__ = "invitations"

    id = Column(Integer, primary_key=True, autoincrement=True)
    inviter_id = Column(Integer)
    invitee_id = Column(Integer)
    status = Column(Integer)
    created_at = Column(DateTime)
    updated_at = Column(DateTime)


class Order(Base):
    __tablename__ = "orders"

    id = Column(Integer, primary_key=True, autoincrement=True)
    user_id = Column(Integer)
    pic = Column(String)
    out_pic = Column(String)
    type = Column(Integer)
    size = Column(String)
    pixel = Column(String)
    status = Column(Integer)
    created_at = Column(DateTime)
    updated_at = Column(DateTime)
